<template>
  <div class="app-container">
    <!-- table -->
    <div class="table">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="realname" align="center" label="姓名"></el-table-column>
        <el-table-column prop="username" align="center" label="电话">
            <template slot-scope="scope">
            <div>{{scope.row.username | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="amountType" align="center" label="积分类型"></el-table-column>
        <el-table-column prop="userMoney" align="center" label="账户积分"></el-table-column>
        <el-table-column prop="allMoney" align="center" label="流水积分"></el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <div>
              <el-button
                v-if="permissionJson.indexOf('AdminMmkaAmountTypesProvider.delete') !=-1"
                type="text"
                @click="detel(scope.row)"
              >删除</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="block" style="margin: 40px 0;">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="params.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import integrationrecord from "@/api/vipmange/integrationrecord";
export default {
  data() {
    return {
      permissionJson: JSON.parse(localStorage.getItem("permissionJson")),
      params: { pageNum: 1, pageSize: 20 },
      tableData: [{ number: 100 }],
      total: 0
    };
  },
  mounted() {
    this.list();
  },
  methods: {
    async list() {
      let res = await integrationrecord.list(this.params);
      console.log(res);
      if (res.data.code == 0) {
        this.tableData = res.data.data.list;
        this.total = res.data.data.count;
      } else {
        this.$message({
          message: res.data.msg,
          type: "warning"
        });
      }
    },
    handleSizeChange(val) {
      this.params.pageNum = 1;
      this.params.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.list();
    },
    detel(data) {
      console.log(data.id);

      this.$confirm("此操作将删除该机里, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(async datas => {
          let res = await integrationrecord.delete({ id: data.id });
          console.log(res);
          this.$message({
            message: res.data.msg,
            type: "warning"
          });
          this.list();
        })
        .catch(() => {});
    }
  }
};
</script>